---
description: Learn how to run the Triplit sync server in Node.js, and the supported storage options - SQLite and LMDB.
---

# Triplit in Node.js

Node is the default runtime for the Triplit server. Triplit provides an [example implementation](https://github.com/aspen-cloud/triplit/tree/main/packages/node-server) and a [docker image](https://hub.docker.com/r/aspencloud/triplit-server). Read more about self-hosting Triplit in the [self-hosting documentation](/self-hosting).

## Supported storage options

### SQLite

SQLite is the default storage option for the Triplit server. It stores all data in a single SQLite database file. This is the recommended storage option for most use cases, as it is fast and easy to set up.

### LMDB

[LMDB](https://github.com/kriszyp/lmdb-js) is a fast, memory-mapped database that is designed for high performance.

## Example

```typescript
import { createServer, createTriplitStorageProvider } from '@triplit/server';

const port = +(process.env.PORT || 8080);

const startServer = await createServer({
  storage: await createTriplitStorageProvider('sqlite'),
  verboseLogs: !!process.env.VERBOSE_LOGS,
  jwtSecret: process.env.JWT_SECRET,
  projectId: process.env.PROJECT_ID,
  externalJwtSecret: process.env.EXTERNAL_JWT_SECRET,
  maxPayloadMb: process.env.MAX_BODY_SIZE,
});

const dbServer = startServer(port);

console.log('running on port', port);
process.on('SIGINT', function () {
  dbServer.close(() => {
    console.log('Shutting down server... ');
    process.exit();
  });
});
```

## Server side clients

Although the Triplit client is typically used in the browser, it can also be used in Node.js.

### Traditional client

If you need real time updates in Node, you can use the Triplit client in Node.js just like you would in the browser. A Triplit client relies on the existence of a [WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) in the environment it is running in. Since Node.js v21, the WebSocket API is available natively. For this reason we recommend using Node.js v21 or later to run the Triplit client in Node.js.

#### Node.js v23 or before

Although the websocket API is available in Node.js after v21, it was released with some [different behavior](https://github.com/nodejs/undici/issues/3546) from browser implementations. However, you can install a newer version of [undici](https://github.com/nodejs/undici) to get a more compliant WebSocket API in Node.js v23 or earlier:

```bash
npm install undici@^7
```

And in your app, you can override the global WebSocket with the one from undici:

```javascript
import { WebSocket as UWebSocket } from 'undici';
globalThis.WebSocket = UWebSocket;
```

#### Node.js v24 or later

You can use the native WebSocket API in Node.js v24 or later without any additional setup.

### HTTP client

However, in many cases you may just need some CRUD access to your database without the need for real-time updates. In this case, you can use the Triplit [HTTP client](/client/http-client).
